const generateSysctlNames: Fig.Generator = {
  script: ["sysctl", "-A", "-N"],
  postProcess: (out) => {
    return out.split("\n").map((line) => {
      return {
        name: line,
        description: "Variable name",
      };
    });
  },
};

const completionSpec: Fig.Spec = {
  name: "sysctl",
  description: "Get or set kernel state",
  options: [
    {
      name: ["-A", "-a"],
      description: "List all the currently available non-opaque values",
    },
    {
      name: "-b",
      description:
        "Force the value of the variable(s) to be output in raw, binary format",
    },
    {
      name: "-d",
      description: "Print the description of the variable instead of its value",
    },
    {
      name: "-e",
      description:
        "Separate the name and the value of the variable(s) with '='",
      args: {
        name: "variable",
        isVariadic: true,
      },
    },
    {
      name: "-h",
      description: "Format output for human, rather than machine, readability",
    },
    {
      name: "-i",
      description: "Ignore unknown OIDs",
    },
    {
      name: "-N",
      description: "Show only variable names, not their values",
    },
    {
      name: "-n",
      description: "Show only variable values, not their names",
    },
    {
      name: "-o",
      description: "Show opaque variables (which are normally suppressed)",
    },
    {
      name: "-q",
      description:
        "Suppress some warnings generated by sysctl to standard error",
    },
    {
      name: "-X",
      description: "Equivalent to -x -a (for compatibility)",
    },
    {
      name: "-x",
      description:
        "As -o, but prints a hex dump of the entire value instead of just the first few bytes",
    },
  ],
  args: {
    name: "Variable names (and values if available)",
    isVariadic: true,
    isOptional: true,
    generators: generateSysctlNames,
  },
};

export default completionSpec;
